package com.interview.juc;

public class VolatileAtomicTest {
    public static volatile int num = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread [] threads = new Thread[10];
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread( () ->{
                for (int j = 0; j < 1000; j++) {
                    increase();
                }
            } );
            threads[i].start();
        }

        for (Thread t: threads){
            t.join();
        }
        System.out.println(num);
    }

    private synchronized static void increase() {
        num ++;
    }
}
